package com.czwx.bee.business.manager.modular.statistics.controller;

import cn.hutool.core.date.DateUtil;
import com.czwx.bee.base.common.dto.ResponseDto;
import com.czwx.bee.base.common.exception.BizExceptionEnum;
import com.czwx.bee.base.web.common.BaseController;
import com.czwx.bee.business.manager.modular.statistics.model.ConversionModel;
import com.czwx.bee.business.manager.modular.statistics.model.query.BizDataQuery;
import com.czwx.bee.business.manager.modular.statistics.service.ConversionService;
import com.czwx.bee.business.manager.modular.sys.model.SecurityUser;
import com.czwx.bee.business.manager.utils.SecurityUtil;
import io.swagger.annotations.*;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @Author:wiki
 * @Date:Create in 2018/7/3 0003 下午 4:48
 */

@RestController
@RequestMapping("/conversion")
@Api(value = "ConversionController",tags = "转化率统计")
public class ConversionController extends BaseController {

      @Autowired
      private ConversionService conversionService;

      @PostMapping("list")
      @ApiOperation(value = "转化率统计列表", notes = "转化率统计列表", httpMethod = "POST")
      @ApiImplicitParams({
              @ApiImplicitParam(name = "Authorization", value = "请输入凭证", required = true, dataType = "String", paramType = "header")
      })
      @ApiResponses(
              {@ApiResponse(code = 200,response = ConversionModel.class,message = "data：中返回list")

              }
      )
      public ResponseDto data(@RequestBody  @Validated BizDataQuery bizDataQuery) throws Exception {
           ResponseDto rs=new ResponseDto(BizExceptionEnum.SUCCESSFUL_OPERATION);
          if(bizDataQuery.getStartTime()==null){
              bizDataQuery.setStartTime(DateUtil.parse("2018-04-30","yyyy-MM-dd"));
          }
          if(bizDataQuery.getEndTime()==null){
              bizDataQuery.setEndTime(new Date());
          }
           SecurityUser securityUser=SecurityUtil.getSecurityUser();
           Map parms=objectToMap(bizDataQuery);
           parms.put("drainageId",securityUser.getDrainageId());
           PageQuery query=  new PageQuery(bizDataQuery.getPage(),bizDataQuery.getSize(),parms);
           conversionService.PageQuery(query);
           rs.setData(query);
           return rs;
      }
}
